<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="net.groupme.gui.constants.VIEW_VOCABULARY"%>
<%@page import="net.groupme.gui.rendering.constants.RENDERING_CONSTANTS"%>
<%@page import="java.util.Iterator"%>
<%@page import="net.groupme.model.User"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<!-- meta tags, link to css:  -->
	<%@ include file="./jsp-includes/metaheader.jsp" %>
	
	<!--  Ajax-Includes -->
    <script type='text/javascript' src='<%= request.getContextPath()%>/dwr/interface/DWRUserManager.js'></script>
    <script type='text/javascript' src='<%= request.getContextPath()%>/dwr/engine.js'></script>
    <script type='text/javascript' src='<%= request.getContextPath()%>/dwr/util.js'></script>
    	<script src="<%= request.getContextPath()%>/scriptaculous/prototype.js" type="text/javascript"></script>
	<script src="<%= request.getContextPath()%>/scriptaculous/scriptaculous.js" type="text/javascript"></script>

<% 
				String username = request.getAttribute(VIEW_VOCABULARY.PARAMETER_USERNAME) + "";
				User user = ObjectFactory.getUser(username);
				Collection<Group> groupsOfUser = user.getGroups(MODEL_CONSTANTS.ROLE_OWNER);
				Collection<Group> subscriptionsOfUser = user.getGroups(MODEL_CONSTANTS.ROLE_SUBSCRIBER);
		%>
		
	<title><%= user.getFirstName() + " " + user.getLastName() %> [GroupMe!]</title>
	<script type="text/javascript" language="javascript"><!--
	//<![CDATA[//>
	
	/**
      * Recomputes the User's Tag Cloud.
      */
     function computeTagCloud(){
     	$("tagCloudLoadingMessage").show();
     	DWRUserManager.getTagCloudForUsername('<%= username %>', showTagCloud);
     }
   		
	/**
	 * Visualize a tag cloud.
	 */
	 function showTagCloud(tagCloud){
	 	$("tagCloudLoadingMessage").hide();
	 	if(tagCloud == null || tagCloud.html == ""){
	 		$('tagcloud').innerHTML = "<i>The user hasn't used any tags!</i>";
	 	}else{
	 		$('tagcloud').innerHTML =  tagCloud.html;
	 	}
	 }
	
	//init stuff:		
	function init() {
		  DWRUtil.useLoadingMessage();
		  computeTagCloud();
	}
	//<!]]>
	--></script>
</head>
<body onload="init()">
	<!-- title image, logo:  -->
	<div id="header">
		<%@ include file="./jsp-includes/titleheader.jsp" %>
	</div>
	
	<!-- Menu: -->
	<div id="menu">
		<%@ include file="./jsp-includes/menu.jsp" %>
	</div>
	<!-- content and sidebar -->
	<div id="main">

		<!-- Sidebar -->
		<div id="sidebar">
		<p><strong><%= username %>'s tags:</strong> </p>
			<div id="tagcloud">
			</div>
			<span id="tagCloudLoadingMessage">
					<img src="<%= request.getContextPath() + RENDERING_CONSTANTS.RELATIVE_PATH_OF_AJAX_LOADING_IMAGE %>" alt="loading"/> 
					<small><i>refreshing tag cloud</i></small>
			</span>
		</div>

		<!-- Content: -->
		<div id="content">
		
			
			<h1><%= username %></h1>
			<table>
				<tr>
					<td>
					<% if(user.getPhoto() != null && !"".equals(user.getPhoto())){ %>
					
						<img src='<%= user.getPhoto() %>' width="150px" alt='user photo'/>
					<%}else{ %>
						<img src='<%= VIEW_VOCABULARY.STANDARD_USER_ICON %>' width="150px" alt='user photo'/>
					<%} %>
					</td>
					<td style="padding-left: 2em">
						<strong>numbers:</strong><br/> 
						- <a href="#groups">groups</a>: <%= groupsOfUser.size() %><br/>
						- <a href="#subscriptions">subscriptions</a>: <%= subscriptionsOfUser.size() %><br/>
						- tags: <%= user.getTags().size() %>
					</td>
				</tr>
				<tr>
					<td style="text-align: center">
						<i><%= user.getFirstName() + " " + user.getLastName() %></i>
					</td>
					<td></td>
				</tr>
			</table>
			<br/>
			<br/>
			<% 
				Iterator it = groupsOfUser.iterator();
			%>
			<h3><%=username %>'s groups<a name="groups"> </a></h3>
			<%@include file="./jsp-includes/list-groups.jsp"%>	
			
			<% 
				it = subscriptionsOfUser.iterator();
			%>
			<h3><%=username %>'s subscriptions<a name="subscriptions"> </a></h3>
			<%@include file="./jsp-includes/list-groups.jsp"%>	
		</div>
	</div>
	<div id="footer">
		<%@ include file="./jsp-includes/footer.jsp" %>
	</div>
</body>
</html>